﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 抽象类
{
    class Program
    {
        static void Main(string[] args)
        {
            Shape[] shapes = new Shape[8];
            for (int i = 0; i < 4; i++)
            {
                shapes[i] = new Circle(i + 1);
                shapes[4 + i] = new Rectangle(i + 2, i + 4);
            }
            foreach (Shape s in shapes)
                Console.WriteLine("{0}:周长{1}面积{2}", s, s.Perimeter, s.Area);
            Console.ReadKey();
        }
    }
    public abstract class Shape
    {
        public abstract double Perimeter { get; }
        public abstract double Area { get; }
    }
    public class Circle : Shape
    {
        public const double Pi = 3.14;
        public double Radius { get; set; }
        public override double Perimeter
        {
            get { return 2 * Pi * Radius; }
        }
        public override double Area
        {
            get { return Pi * Radius * Radius; }
        }
        public Circle(double radius)
        {
            this.Radius = radius;
        }
        public override string ToString()
        {
            return string.Format("圆形(r={0})", Radius);
        }
    }

    public class Rectangle : Shape
    {
        private double Width { get; set; }
        private double Height { get; set; }
        public override double Perimeter
        {
            get { return 2 * (Height * Width); }
        }
        public override double Area
        {
            get { return Height * Width; }
        }
        public Rectangle(double width, double height)
        {
            Width = width;
            Height = height;
        }
        public override string ToString()
        {
            return string.Format("矩形(w={0},h={1})", Width, Height);
        }
    }
}
